<template>
<div class="main">
  <!-- 头部导航栏 -->
  <head-component :noBack="false"  title="修改密码"/>

  <div class="con">
    <div class="list">
      <span class="f32 col_33">旧密码</span>
      <input type="password" v-model="oldPass" placeholder="请输入旧密码"  class="f32 col_33">
      <p class="f32" @click="$router.push('/forget')">忘记密码</p>
    </div>
    <div class="list">
      <span  class="f32 col_33">新密码</span>
      <input type="password" v-model="newPass" placeholder="请输入6-12位新密码"  class="f32 col_33">
    </div>
    <div class="list">
      <span  class="f32 col_33">确认密码</span>
      <input type="password" v-model="surePass" placeholder="请确认新密码"  class="f32 col_33">
    </div>
  </div>

  <div class="global_btn" @click="tijiao">提交</div>

</div>
</template>

<script>
import headComponent from '@/components/layout/head'
export default {
    name: "changePsd.vue",
    components: {
      headComponent
    },
    data(){
      return {
        oldPass: '',
        newPass: '',
        surePass:　''
      }
    },
    methods: {
      tijiao(){
        let $this = this;
        if($this.oldPass.length === 0) {
          this.$toast({
            message: '请输入旧密码',
            duration: 800
          });
          return;
        } else if (!/^[\w]{6,12}$/.test($this.newPass)){
          this.$toast({
            message: '请输入6-12位新密码',
            duration: 800
          });
          return;
        } else if($this.newPass !== $this.surePass){
          this.$toast({
            message: '两次输入密码不一致',
            duration: 800
          });
          return;
        }
        let uid = localStorage.getItem('uid');
        let token = localStorage.getItem('token');
        let data = { u_id:uid, token:token, pass:$this.oldPass, pass1:$this.newPass, pass2:$this.surePass };
        $this.$axios.post('index.php?m=user&c=edit_pass', data).then( res => {
          if(res.data.code === 0){ // 未通过
            this.$toast({
              message: res.data.msg,
              duration: 1000
            });
          } else if(res.data.code === 1){
            this.$toast({
              message: res.data.msg,
              duration: 1000,
              onClose:()=>{
                $this.$router.push('/set');
              }
            });

          }
        })
      }
    }
}
</script>

<style scoped  lang="less">
  .layout-head{border-bottom: 0.02rem solid #f5f5f5;}
  .con{
    margin: 1.8rem auto 0;width: 90%;
    .list{width: 100%;height: 1.3rem;line-height: 1.3rem; margin-bottom:0.533rem; position: relative;border-radius: 0.16rem;
      box-shadow:0px 0px 14px #e9e9e9;background: #fff;
      span{
        float: left;
        margin-left: 0.4rem;
        width: 2.2rem;
      }
      input{width: 60%; height:  1.2rem;color: #999;float: left;line-height: 1.3rem;}
      p{position: absolute; right:0.4rem; color: #409aff;}
    }
  }
  .global_btn{width: 90%;margin: 1rem auto 0;}
</style>
